<template>
  <div class="bottom-bar">
    <div class="check-content">
      <check-button class="check-button" :isChecked="isSelectAll" @click.native="checedkAll"/>
      全选
    </div>

    <div class="price">
      合计: {{totalPrice}}
    </div>

    <div class="calculate">
      去计算: ({{checkLength}})
    </div>
  </div>
</template>

<script>
import CheckButton from 'components/content/checkButton/CheckButton.vue'
export default {
  components:{
    CheckButton,
  },
  name: 'CartBottomBar',
  computed:{
    totalPrice(){
      return '￥'+(this.$store.state.cartList.filter(item=>item.checked).reduce((preValue, item)=>{ return preValue+item.price*item.count},0)).toFixed(2)
    },
    checkLength(){
      return this.$store.state.cartList.filter(item=>item.checked).length
    },
    isSelectAll(){
      if(this.$store.state.cartList.length === 0) return false
      return   !this.$store.state.cartList.find(item=>item.checked === false)
    }
  },
  methods: {
    checedkAll(){
      let flag = !this.isSelectAll
      this.$store.state.cartList.map(item=>item.checked = flag)
    }
  }
}
</script>

<style scoped>
  .bottom-bar {
    height: 40px;
    background-color: #eee;
    position: relative;
    line-height: 40px;
    display: flex;
    font-size: 14px;
  }
  .check-button {
    width: 20px;
    height: 20px;
    line-height: 20px;
    margin-right: 10px;

  }
  .check-content{
    display: flex;
    margin-left: 10px;
    align-items: center;
    width: 60px;
  }

  .price{
    margin-left: 20px;
    flex: 1;
  }

  .calculate {
    width: 90px;
    text-align: center;
    background-color: red;
  }
</style>
